﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Enterprise.DataFactory;
using Enterprise.Model.Department;
using Enterprise.Infrastructure;
namespace Enterprise.Data.Department
{
    /// <summary>
    /// 部门数据表操作类
    /// </summary>
    public class DepartmentData
    {

        /// <summary>
        ///  部门数据列表
        /// </summary>
        /// <returns></returns>
        public List<DepartmentEntity> DepartmentList()
        {
            List<DepartmentEntity> list = new List<DepartmentEntity>();
            string cmd = "Select * from SYS_DEPARTMENT";
            IDataReader dr = DbExecute.DataReader(cmd);
            while (dr.Read())
            {
                DepartmentEntity entity = new DepartmentEntity();
                if (!Convert.IsDBNull(dr["DEPTID"])) entity.DEPTID = Convert.ToInt32(dr["DEPTID"]);
                if (!Convert.IsDBNull(dr["DNAME"])) entity.DNAME = Convert.ToString(dr["DNAME"]);
                if (!Convert.IsDBNull(dr["DPARENTID"])) entity.DPARENTID = Convert.ToInt32(dr["DPARENTID"]);
                if (!Convert.IsDBNull(dr["DDEPTH"])) entity.DDEPTH = Convert.ToInt32(dr["DDEPTH"]);
                if (!Convert.IsDBNull(dr["DROOTID"])) entity.DROOTID = Convert.ToInt32(dr["DROOTID"]);
                if (!Convert.IsDBNull(dr["DMANAGER"])) entity.DMANAGER = Convert.ToInt32(dr["DMANAGER"]);
                if (!Convert.IsDBNull(dr["DHEADERMANAGER"])) entity.DHEADERMANAGER = Convert.ToInt32(dr["DHEADERMANAGER"]);
                if (!Convert.IsDBNull(dr["DORDERBY"])) entity.DORDERBY = Convert.ToInt32(dr["DORDERBY"]);
                list.Add(entity);
            }
            dr.Close();
            return list;
        }

        /// <summary>
        /// 部门数据操作方法
        /// </summary>
        /// <param name="cmd"></param>
        public void DepartmentExecute(string cmd)
        {
            DbExecute.Execute(cmd);
        }

    }
}
